package com.inspur.ourhis_afterend.Controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.inspur.ourhis_afterend.Service.DoctorDutyService;
import com.inspur.ourhis_afterend.Service.DoctorsService;
import com.inspur.ourhis_afterend.Tools.PageAction;
import com.inspur.ourhis_afterend.Tools.Result;
import com.inspur.ourhis_afterend.model.DoctorDuty;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;

@RestController
@RequestMapping("/duty")
public class DoctorDutyController {
    @Resource
    DoctorDutyService doctorDutyService;
    @Resource
    DoctorsService doctorsService;
    @ApiParam("分页数据，医生id，值班时间")
    @ApiOperation("分页值班查询")
    @PostMapping("/search")
    public Result selectBySelective(@RequestBody PageAction pageAction,
                                    @RequestParam(value = "docid",required = false) Integer docid,
                                    @RequestParam(value = "dutyDate",required = false)Date dutydate){
        System.out.println(pageAction);
        IPage<DoctorDuty> page = new Page<>(pageAction.getPageNo(),pageAction.getPageSize());
        try {
            return Result.success(doctorDutyService.selectBySelective(page,docid,dutydate));
        } catch (Exception e) {
            e.printStackTrace();
            return Result.failure(e.toString());
        }
    }
    @ApiParam("值班实体")
    @ApiOperation("添加值班")
    @PostMapping("/add")
    public Result addDuty(@RequestBody DoctorDuty doctorDuty){
        try {
            return Result.success(doctorDutyService.addDuty(doctorDuty));
        } catch (Exception e) {
            e.printStackTrace();
            return Result.failure(e.toString());
        }
    }
    @ApiParam("值班id")
    @ApiOperation("删除值班")
    @DeleteMapping("/del")
    public Result delDuty(@RequestParam("ddid") Integer ddid){
        try {
            doctorDutyService.delDuty(ddid);
            return Result.success("成功");
        } catch (Exception e) {
            e.printStackTrace();
            return Result.failure("失败"+e.toString());
        }
    }

    @ApiParam("值班id")
    @ApiOperation("按照id查询值班人")
    @PostMapping("/findById")
    public Result findById(@RequestParam("ddid") Integer  ddid){
        try {
            return Result.success(doctorDutyService.findById(ddid));
        } catch (Exception e) {
            e.printStackTrace();
            return Result.failure("失败"+e.toString());
        }
    }


}
